#include "contiki.h"
#include "shell.h"

#include "collect-common.h"
#include "trickle-ipv6.h"

#include <stdio.h>

#define DEBUG 0
#if DEBUG
#define PRINTF(...) printf(__VA_ARGS__)
#else
#define PRINTF(...)
#endif

/*---------------------------------------------------------------------------*/
PROCESS(shell_ipv6_set_time_process, "set_time ipv6");
SHELL_COMMAND(ipv6_set_time_command,
	      "time",
	      "time [seconds]: set time in seconds since 1970",
	      &shell_ipv6_set_time_process);
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_ipv6_set_time_process, ev, data)
{

    char *line;
    unsigned long aux_time;

    PROCESS_BEGIN();

    line= data;

    while(*line == ' ') {
      line++;
    }
    aux_time = strtolong(line);
    PRINTF("Tiempo ingresado %lu\n", aux_time);
    set_time(aux_time);
    aux_time = get_time();
    printf("Tiempo actualizado a %lu\n", aux_time);
    trickle_ipv6_send();

    PROCESS_END();
}
/*---------------------------------------------------------------------------*/
void
shell_ipv6_set_time_init(void)
{
  shell_register_command(&ipv6_set_time_command);
}
/*---------------------------------------------------------------------------*/
